﻿using System;
using System.Windows.Forms;
using System.Management;

namespace FscNET.Tracer
{
    static class Program
    {
        internal static bool _runAsServer = true;
        
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            ManagementEventWatcher watcher = null;
            try
            {
                watcher_EventArrived(null, null);

                //watch for key value changes
                WqlEventQuery keyValChangedQuery = new WqlEventQuery(
                    "SELECT * FROM RegistryValueChangeEvent WHERE " +
                    "Hive = 'HKEY_CURRENT_USER' AND " +
                    "KeyPath = 'Software\\Fabasoft\\TRACER\\Output' AND ValueName='(Default)'");
                watcher = new ManagementEventWatcher(keyValChangedQuery);
                watcher.EventArrived += watcher_EventArrived;
                watcher.Start();
            }
            catch { }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());

            try
            {
                if (watcher != null) watcher.Stop();
            }
            catch { }
        }

        static void watcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            Tracing.OutputManager.RefreshValue();
        }
    }
}
